namespace ACRSAP.Administration.Users
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public class UserDetail : Page
    {
        [AccessedThroughProperty("btnCancel")]
        private Button _btnCancel;
        [AccessedThroughProperty("btnSave")]
        private Button _btnSave;
        [AccessedThroughProperty("CompareValidator1")]
        private CompareValidator _CompareValidator1;
        [AccessedThroughProperty("dropRoles")]
        private DropDownList _dropRoles;
        [AccessedThroughProperty("formsPassword")]
        private HtmlTable _formsPassword;
        [AccessedThroughProperty("lblError")]
        private Label _lblError;
        [AccessedThroughProperty("RequiredFieldValidator1")]
        private RequiredFieldValidator _RequiredFieldValidator1;
        [AccessedThroughProperty("RequiredFieldValidator2")]
        private RequiredFieldValidator _RequiredFieldValidator2;
        [AccessedThroughProperty("txtConfirmPassword")]
        private TextBox _txtConfirmPassword;
        [AccessedThroughProperty("txtEmail")]
        private TextBox _txtEmail;
        [AccessedThroughProperty("txtPassword")]
        private TextBox _txtPassword;
        [AccessedThroughProperty("txtUsername")]
        private TextBox _txtUsername;
        private object designerPlaceholderDeclaration;

        public UserDetail()
        {
            base.Load += new EventHandler(this.Page_Load);
            base.Init += new EventHandler(this.Page_Init);
        }

        public void CancelEdit(object s, EventArgs e)
        {
            this.Response.Redirect("UserList.aspx");
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        private void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.dropRoles.DataSource = Role.GetAllRoles();
                this.dropRoles.DataTextField = "Name";
                this.dropRoles.DataBind();
                if (this.Request.QueryString["id"] != null)
                {
                    this.UserId = int.Parse(this.Request.QueryString["id"]);
                }
                if (this.UserId != 0)
                {
                    ITUser objUser = ITUser.GetUserById(this.UserId);
                    this.txtUsername.Text = objUser.Username;
                    this.dropRoles.SelectedValue = objUser.RoleName;
                    this.txtEmail.Text = objUser.Email;
                    if (string.Compare(this.User.Identity.Name, objUser.Username, true) == 0)
                    {
                        this.IsCurrentUser = true;
                    }
                }
                if (StringType.StrCmp(this.User.Identity.AuthenticationType, "Forms", false) != 0)
                {
                    this.formsPassword.Visible = false;
                }
            }
        }

        public void SaveUser(object s, EventArgs e)
        {
            bool isCurrentUser = false;
            if (this.Page.IsValid)
            {
                ITUser objUser = new ITUser();
                if (this.UserId != 0)
                {
                    objUser = ITUser.GetUserById(this.UserId);
                }
                objUser.Username = this.txtUsername.Text;
                objUser.RoleName = this.dropRoles.SelectedItem.Text;
                objUser.Email = this.txtEmail.Text;
                if (StringType.StrCmp(this.txtPassword.Text, string.Empty, false) != 0)
                {
                    objUser.Password = this.txtPassword.Text;
                }
                if (!objUser.Save())
                {
                    this.lblError.Text = "Could not save user";
                }
                else
                {
                    if (isCurrentUser)
                    {
                        FormsAuthentication.SignOut();
                    }
                    this.Response.Redirect("UserList.aspx");
                }
            }
        }

        protected virtual Button btnCancel
        {
            get
            {
                return this._btnCancel;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnCancel != null)
                {
                    this._btnCancel.Click -= new EventHandler(this.CancelEdit);
                }
                this._btnCancel = value;
                if (this._btnCancel != null)
                {
                    this._btnCancel.Click += new EventHandler(this.CancelEdit);
                }
            }
        }

        protected virtual Button btnSave
        {
            get
            {
                return this._btnSave;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnSave != null)
                {
                    this._btnSave.Click -= new EventHandler(this.SaveUser);
                }
                this._btnSave = value;
                if (this._btnSave != null)
                {
                    this._btnSave.Click += new EventHandler(this.SaveUser);
                }
            }
        }

        protected virtual CompareValidator CompareValidator1
        {
            get
            {
                return this._CompareValidator1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._CompareValidator1 != null)
                {
                }
                this._CompareValidator1 = value;
                if (this._CompareValidator1 != null)
                {
                }
            }
        }

        protected virtual DropDownList dropRoles
        {
            get
            {
                return this._dropRoles;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._dropRoles != null)
                {
                }
                this._dropRoles = value;
                if (this._dropRoles != null)
                {
                }
            }
        }

        protected virtual HtmlTable formsPassword
        {
            get
            {
                return this._formsPassword;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._formsPassword != null)
                {
                }
                this._formsPassword = value;
                if (this._formsPassword != null)
                {
                }
            }
        }

        public bool IsCurrentUser
        {
            get
            {
                if (this.ViewState["IsCurrentUser"] == null)
                {
                    return false;
                }
                return BooleanType.FromObject(this.ViewState["IsCurrentUser"]);
            }
            set
            {
                this.ViewState["IsCurrentUser"] = value;
            }
        }

        protected virtual Label lblError
        {
            get
            {
                return this._lblError;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lblError != null)
                {
                }
                this._lblError = value;
                if (this._lblError != null)
                {
                }
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator1
        {
            get
            {
                return this._RequiredFieldValidator1;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator1 != null)
                {
                }
                this._RequiredFieldValidator1 = value;
                if (this._RequiredFieldValidator1 != null)
                {
                }
            }
        }

        protected virtual RequiredFieldValidator RequiredFieldValidator2
        {
            get
            {
                return this._RequiredFieldValidator2;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._RequiredFieldValidator2 != null)
                {
                }
                this._RequiredFieldValidator2 = value;
                if (this._RequiredFieldValidator2 != null)
                {
                }
            }
        }

        protected virtual TextBox txtConfirmPassword
        {
            get
            {
                return this._txtConfirmPassword;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtConfirmPassword != null)
                {
                }
                this._txtConfirmPassword = value;
                if (this._txtConfirmPassword != null)
                {
                }
            }
        }

        protected virtual TextBox txtEmail
        {
            get
            {
                return this._txtEmail;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtEmail != null)
                {
                }
                this._txtEmail = value;
                if (this._txtEmail != null)
                {
                }
            }
        }

        protected virtual TextBox txtPassword
        {
            get
            {
                return this._txtPassword;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtPassword != null)
                {
                }
                this._txtPassword = value;
                if (this._txtPassword != null)
                {
                }
            }
        }

        protected virtual TextBox txtUsername
        {
            get
            {
                return this._txtUsername;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._txtUsername != null)
                {
                }
                this._txtUsername = value;
                if (this._txtUsername != null)
                {
                }
            }
        }

        public int UserId
        {
            get
            {
                if (this.ViewState["UserId"] == null)
                {
                    return 0;
                }
                return IntegerType.FromObject(this.ViewState["UserId"]);
            }
            set
            {
                this.ViewState["UserId"] = value;
            }
        }
    }
}

